# Attempts to convert plain-text lists to HTML lists.

BEGIN {
	in_list=0
}

# (Possible) start of a list.
! in_list && /^ *- / {
	in_list = 1
	delete lbuf
	lcount=0
	in1 = index($0, "-")
	in2 = in1 + 2
	lbuf[lcount++] = $0
	next
}

in_list && /^ *- / {
	lbuf[lcount++] = $0
	next
}

in_list && /^ / && match($0, /\w/) == in2 {
	lbuf[lcount++] = $0
	next
}

in_list && /^ / {
	x = match($0, /\w/);
	print "CHECK:", x, in1, in2, $0
}


# Definite end of a list.
in_list && ! /^\s/ {
	in_item = 0
	print "<!-- This list was generated automatically -->"
	print "<ul>"
	for (i in lbuf) {
		line = lbuf[i]
		if (line ~ /^ *-/) {
			if (in_item)
				print "</li>"
			sub(/^ *- /, "<li>", line)
			in_item=1
			print line
		} else {
			print line
		}
	}
	print "</ul>"
	in_list=0
}

{print}

